package com.kenyi.co.ui.video.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.util.Util;
import com.kenyi.co.GlideApp;
import com.kenyi.co.R;
import com.kenyi.co.ui.video.VideoDetailBean;
import com.kenyi.co.utils.BaseMultiAdapter;
import com.kenyi.co.utils.LogU;
import com.kenyi.co.utils.SuperViewHolder;

/**
 * Created by Administrator on 2018/1/29.
 */

public class VideoDetailAdapter extends BaseMultiAdapter<VideoDetailBean.DatasBean.RecommendBean> {


    public VideoDetailAdapter(Context context) {
        super(context);

        addItemType(1, R.layout.fragment_right_item_2);
        addItemType(2, R.layout.video_list_ad_1);
        addItemType(3, R.layout.video_list_ad_2);
        addItemType(4, R.layout.video_list_ad_3);
        addItemType(5, R.layout.video_list_ad_4);


    }


    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        VideoDetailBean.DatasBean.RecommendBean item = mDataList.get(position);
        int ItemType = 1;

        switch (item.getItemType()) {
            case 1:
                bindTextItem1(holder, item);
                break;
            case 2:
                bindTextItem2(holder, item);
                break;
            case 3:
                bindTextItem3(holder, item);
                break;
            case 4:
                bindTextItem4(holder, item);
                break;
            case 5:
                bindTextItem5(holder, item);
                break;
            default:
                break;
        }

    }

    private void bindTextItem1(SuperViewHolder holder, VideoDetailBean.DatasBean.RecommendBean item) {
        final ImageView iv_item_vodeo = holder.getView(R.id.iv_item_vodeo);
        TextView tv_video_right_title = holder.getView(R.id.tv_video_right_title);
        TextView tv_video_right_sub_title = holder.getView(R.id.tv_video_right_sub_title);
        TextView tv_video_right_num = holder.getView(R.id.tv_video_right_num);
        TextView tv_video_right_time = holder.getView(R.id.tv_video_right_time);
        tv_video_right_time.setText(item.getVideoTime());
        tv_video_right_title.setText(item.getTitle());
        tv_video_right_sub_title.setText(item.getDesc());
        tv_video_right_num.setText("播放次数：" + item.getReadCount() + "次");
        try {
            if (Util.isOnMainThread() && mContext != null) {
                GlideApp.with(mContext)
                        .load(item.getVideoImg())
                        .placeholder(R.drawable.iv_bg_video_right)
                        .error(R.drawable.iv_bg_video_right)
                        .into(iv_item_vodeo);
            }

        } catch (Exception e) {

        }

    }

    private void bindTextItem2(SuperViewHolder holder, VideoDetailBean.DatasBean.RecommendBean item) {

        TextView tv_ad_1_title = holder.getView(R.id.tv_ad_1_title);
        ImageView iv_ad_1_1 = holder.getView(R.id.iv_ad_1_1);
        ImageView iv_ad_1_2 = holder.getView(R.id.iv_ad_1_2);
        ImageView iv_ad_1_3 = holder.getView(R.id.iv_ad_1_3);
        tv_ad_1_title.setText(item.getAds().get(0).getTitle());
        try {
            if (Util.isOnMainThread() && mContext != null) {
                GlideApp.with(mContext)
                        .load(item.getAds().get(0).getImgs().get(0))
                        .placeholder(R.drawable.iv_ad_1_1)
                        .error(R.drawable.iv_ad_1_1)
                        .into(iv_ad_1_1);
                GlideApp.with(mContext)
                        .load(item.getAds().get(0).getImgs().get(1))
                        .placeholder(R.drawable.iv_ad_1_2)
                        .error(R.drawable.iv_ad_1_2)
                        .into(iv_ad_1_2);
                GlideApp.with(mContext)
                        .load(item.getAds().get(0).getImgs().get(2))
                        .placeholder(R.drawable.iv_ad_1_3)
                        .error(R.drawable.iv_ad_1_3)
                        .into(iv_ad_1_3);
            }

        } catch (Exception e) {

        }


    }

    private void bindTextItem3(SuperViewHolder holder, VideoDetailBean.DatasBean.RecommendBean item) {
        ImageView iv_item_vodeo = holder.getView(R.id.iv_item_vodeo);
        TextView tv_video_right_title = holder.getView(R.id.tv_video_right_title);
        tv_video_right_title.setText(item.getAds().get(0).getTitle());
        try {
            if (Util.isOnMainThread() && mContext != null) {
                GlideApp.with(mContext)
                        .load(item.getAds().get(0).getImgs().get(0))
                        .placeholder(R.drawable.iv_bg_video_right)
                        .error(R.drawable.iv_bg_video_right)
                        .into(iv_item_vodeo);
            }

        } catch (Exception e) {

        }

    }

    private void bindTextItem4(SuperViewHolder holder, VideoDetailBean.DatasBean.RecommendBean item) {
        ImageView iv_item_like = holder.getView(R.id.iv_item_like);
        TextView tv_video_title = holder.getView(R.id.tv_video_title);
        tv_video_title.setText(item.getAds().get(0).getTitle());

        try {
            if (Util.isOnMainThread() && mContext != null) {
                GlideApp.with(mContext)
                        .load(item.getAds().get(0).getImgs().get(0))
                        .placeholder(R.drawable.iv_bg_video_right)
                        .error(R.drawable.iv_bg_video_right)
                        .into(iv_item_like);
            }

        } catch (Exception e) {

        }
    }

    private void bindTextItem5(SuperViewHolder holder, VideoDetailBean.DatasBean.RecommendBean item) {

    }


}
